# -*-coding:utf-8-*-
# class Turtle:
#     color = 'green'
#     weight = 10
#     legs = True
#     mouth = '大嘴'
#
#     def climb(self):
#         print("我正在很努力地向前爬...")
#
#     def run(self):
#         print("我正在飞快地地向前跑...")
#
#     def bite(self):
#         print("咬死你咬死你！！")
#
#     def eat(self):
#         print("有得吃，真满足")
#
#     def sleep(self):
#         print("困了，睡了，晚安，")
#
#
# tt = Turtle()
# tt.sleep()
# tt.run()
# tt.eat()


# 面向对象编程
# class Ball:
#     def setName(self, name):
#         self.name = name
#
#     def kick(self):
#         print("我叫%s，噢~谁踢我？！" % self.name)
#
#
# a = Ball()
# a.setName("飞火流星")
# b = Ball()
# b.setName("团队之星")
# c = Ball()
# c.setName("土豆")
# a.kick()
# b.kick()
# c.kick()


# class Potato:
#     def __init__(self, name):
#         self.name = name
#
#     def click(self):
#         print("我叫%s，噢~谁踢我？！" % self.name)
#
#
# p = Potato("土豆")
# p.click()


# 公有和私有
# class Person:
#     __name = "小甲鱼"  # （__私有变量）
#
#
# p = Person()
# p.name


# class Person:
#     def __init__(self, name):
#         self.__name = name
#
#     def getName(self):
#         return self.__name
#
#
# p = Person("小甲鱼")
# print(p._Person__name)


# 继承
# class Parent:
#     def hello(self):
#         print("正在调用父类的方法...")
#
#
# class Child(Parent):
#     def hello(self):
#         print("正在调用子类的方法...")
#
#
# p = Parent()
# p.hello()
# c = Child()
# c.hello()

# import random as r
#
#
# class Fish:
#     def __init__(self):
#         self.x = r.randint(0, 10)
#         self.y = r.randint(0, 10)
#
#     def move(self):
#         # 假设所有的鱼都是向西游
#         self.x -= 1
#         print("我的位置是：", self.x, self.y)
#
#
# class GoldFish(Fish):
#     pass
#
#
# class Carp(Fish):
#     pass
#
#
# class Salmon(Fish):
#     pass
#
#
# class Shark(Fish):
#     def __init__(self):
#         #        Fish.__init__(self) # 法1.调用未绑定的父类方法
#         super().__init__() #法2.super函数能够吧帮助自动找到基类的方法
#         self.hungry = True
#
#     def eat(self):
#         if self.hungry:
#             print("吃货的梦想就是天天有得吃")
#             self.hungry = False
#         else:
#             print("太撑了，吃不下！")
#
#
# fish = Fish()
# # fish.move()
# goldfish = GoldFish()
# # goldfish.move()
# shark = Shark()
# # shark.eat()
# # shark.eat()
# shark.move()

# 多重继承
# class Base1:
#     def fool(self):
#         print("我是fool，我在Base1中...")
#
#
# class Base2:
#     def fool2(self):
#         print("我是fool2，我在Base2中...")
#
#
# class C(Base1, Base2):
#     pass
#
#
# c = C()
# c.fool()
# c.fool2()

# 11.6 组合 把需要的类放进去实例化
# class Turtle:
#     def __init__(self, x):
#         self.num = x
#
#
# class Fish:
#     def __init__(self, y):
#         self.num = y
#
#
# class Pool:
#     def __init__(self, x, y):
#         self.turtle = Turtle(x)
#         self.fish = Fish(y)
#
#     def print_num(self):
#         print("水池里总共有乌龟%d只，小鱼%d条！" % (self.turtle.num, self.fish.num))
#
#
# pool = Pool(1, 10)
# pool.print_num()

# 11.7 类、类对象和实例对象
# class C:  # C 类定义
#     count = 0
#
#
# a = C()  # C 类对象
# b = C()
# c = C()
# print(a.count, b.count, c.count)  # a,b,c 实例对象
# c.count += 10
# print(a.count, b.count, c.count)
# C.count += 100
# print(a.count, b.count, c.count)


# 注：对实例对象c的count属性进行赋值后，就相当于覆盖了类对象C的count属性
# 如果没有赋值覆盖，那么引用的是类对象的count属性

# 类中定义的属性是静态变量，类的属性是与类对象进行绑定，并不会依赖任何它的实例对象


# class C:
#     def x(self):
#         print('Xman')
#
#
# c = C()
# c.x()
# c.x=1
# print (c.x)
# c.x()
# 注： 不要试图在一个类里边定义出所有能想到的特性和方法，应该利用继承和组合机制来进行扩展
# 用不同的词性命名，如属性名用名词、方法名用动词，并使用驼峰法命名

# 11.8 绑定
# class BB:
#     def printBB():
#         print("no zuo no die")
#
#
# BB.printBB()
# bb = BB()
# bb.printBB()
# 由于Python的绑定机制，这里自动把bb对象作为第一个参数传入，所以才会出现TypeError

# class CC:
#     def setXY(self, x, y):
#         self.x = x
#         self.y = y
#
#     def printXY(self):
#         print(self.x, self.y)
#
#
# dd = CC()
# # print (dd.__dict__)
# # print (CC.__dict__)
# # __dict__ 属性是由一个字典组成，字典中仅有实例对象的属性，不显示类属性和特殊属性，
# # 键表示的是属性名，值表示属性相应的数据值
# dd.setXY(4, 5)
# print(dd.__dict__)
# print(CC.__dict__)


